home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / mbb35src / mbbinit.asm < prev    next >
Encoding:
Assembly Source File  |  1991-02-17  |  12.6 KB  |  292 lines

  1. ;==========================================================================;
  2. ; Initialization Routines                                                  ;
  3. ;                                                                          ;
  4. ;   Copyright 1983 by William E. Westfield.  All rights reserved.          ;
  5. ;   Copyright 1986, 1987, 1988, 1991 by H. Roy Engehausen.                 ;
  6. ;   All rights reserved.                                                   ;
  7. ;                                                                          ;
  8. ;   This software may be freely distributed and used, but it may not       ;
  9. ;   under any circumstances be sold by anyone other than the author.       ;
  10. ;   It may be distributed by a commercial company as long as it is         ;
  11. ;   for no cost.                                                           ;
  12. ;==========================================================================;
  13.  
  14. ;--------------------------------------------------------------------------;
  15. ; Handle desqview stuff                                                    ;
  16. ;--------------------------------------------------------------------------;
  17.  
  18.   IF present_dv                     ; Only if desqview is wanted
  19.  
  20.         TEST    parm_flag,parm_flag_d ; Desqview?
  21.         JNZ     dv_to_work            ; Yes
  22.  
  23. dv_store    MACRO NUM
  24. dv_lbl      = dv_hook&num
  25.             MOV   WORD PTR dv_lbl,AX
  26.             MOV   dv_lbl+2,AL
  27.             ENDM
  28.  
  29. dv_nop      LABEL WORD
  30.             NOP
  31.             NOP
  32.             MOV   AX,dv_nop
  33.  
  34.             REPT dv_cnt
  35.             dv_store %dv_cnt
  36. dv_cnt = dv_cnt - 1
  37.             ENDM
  38.  
  39. dv_to_work:
  40.  
  41.   ENDIF
  42.  
  43. ;--------------------------------------------------------------------------;
  44. ; Initialize the buffer pool -- This starts to clobber the initialization  ;
  45. ; code.  We have to bury some jumps in the right places                   ;
  46. ;--------------------------------------------------------------------------;
  47.  
  48.         MOV     AX,OFFSET buffer_start ;
  49.         MOV     CL,4                ;
  50.         SHR     AX,CL               ;
  51.         MOV     BX,CS               ;
  52.         ADD     AX,BX               ; Get segment address of buffers
  53.         MOV     pool_start,AX       ; Segment where the pool starts
  54.         MOV     free_buffer_head,AX ; Set head of the chain
  55.         MOV     ES,AX               ; ES now head of chain
  56.  
  57.         MOV     CL,buffer_count     ; Number of buffers to build
  58.         SUB     CH,CH               ; Clear top of register
  59.         MOV     DX,buffer_size_para ; Increment bewteen buffer addresses
  60.         ADD     AX,DX               ; Next buffer address
  61.  
  62. ;--------------------------------------------------------------------------;
  63. ; This little loop chains all the buffers together on the free list        ;
  64. ;--------------------------------------------------------------------------;
  65.  
  66. build_loop:
  67.  
  68.         MOV     ES:buffer_next,AX   ; Chain by buffer address
  69.  
  70.         MOV     ES,AX               ; ES now next buffer in sequence
  71.  
  72.         ADD     AX,DX               ; Calculate next buffer address
  73.  
  74.         LOOP    build_loop          ; Loop for all buffers
  75.  
  76.         MOV     ES:buffer_next,0    ; Zero the last buffer
  77.  
  78. ;--------------------------------------------------------------------------;
  79. ; Now snatch the BIOS comm vector                                          ;
  80. ;--------------------------------------------------------------------------;
  81.  
  82.         CLI                         ; No interrupts while snatching!
  83.  
  84.         MOV     AH,dos_get_vector   ; DOS call #35H -- Get vector
  85.         MOV     AL,rs232_vector_no  ; vector #
  86.         INT     dos_vector_no       ; Do it
  87.  
  88.         MOV     old_bios_vector,BX   ;      and save it
  89.         MOV     old_bios_vector+2,ES ;
  90.  
  91.         MOV     AH,dos_set_vector   ; DOS call #25H -- Set vector
  92.         MOV     AL,rs232_vector_no  ; RS232 vector #
  93.         MOV     DX,OFFSET rsint     ; Our vector address
  94.                                     ; DS already points to correct segment
  95.         INT     dos_vector_no       ; Do it
  96.  
  97. ;--------------------------------------------------------------------------;
  98. ; Loop initializing each COM port                                          ;
  99. ;--------------------------------------------------------------------------;
  100.  
  101.         MOV     SI,OFFSET com_start ; Place to start the comm loop
  102.  
  103. init_loop:
  104.  
  105.         MOV     DI,com_init_count   ; Get number of ports left to do
  106.  
  107. ;--------------------------------------------------------------------------;
  108. ; Set the hardware interrupt vector                                        ;
  109. ;--------------------------------------------------------------------------;
  110.  
  111.         MOV     old_interrupt_vec_seg[DI],0 ; Start with a zero for segment
  112.  
  113.         MOV     AL,hiv[SI]          ; Get the hardware interrupt vector address
  114.         MOV     AH,dos_get_vector   ; DOS call #35H -- Get vector
  115.         INT     dos_vector_no       ; Do it
  116.  
  117.         MOV     AX,ES               ; Get the segment of the current vector
  118.         MOV     DX,DS               ; Get our segment
  119.         CMP     DX,AX               ; See if it is already us...
  120.         JE      init_interrupt_skip ;      If it is, skip it
  121.  
  122.         MOV     old_interrupt_vec_off[DI],BX ; Save previous hardware vectors
  123.         MOV     old_interrupt_vec_seg[DI],ES ; Save previous hardware vectors
  124.  
  125.         MOV     AL,hiv[SI]          ; Get the hardware interrupt vector address
  126.         MOV     AH,dos_set_vector   ; DOS call #25H -- Set vector
  127.         MOV     DX,interrupt_vector[DI] ; Get our address
  128.         INT     dos_vector_no       ; Do it
  129.  
  130. init_interrupt_skip:
  131.  
  132.         MOV     interrupt_vector[DI],SI ; Save the com block address here!
  133.  
  134.         MOV     AX,DI               ; Bump counter to next value
  135.         INC     AX                  ; Bump counter
  136.         INC     AX                  ; Twice for words
  137.         MOV     com_init_count,AX   ; and then save it
  138.  
  139. ;--------------------------------------------------------------------------;
  140. ; Fix up BIOS pointers                                                     ;
  141. ;--------------------------------------------------------------------------;
  142.  
  143.         MOV     CX,baseaddr[SI]     ; Get base address for chip
  144.  
  145.         SUB     BH,BH               ;
  146.         MOV     BL,comnumber[SI]    ; Get the com number
  147.         CMP     BL,rs232_bios_max-1 ; Within the table?
  148.         JA      init_not_bios       ;      Nope, skip it
  149.  
  150.         SHL     BL,1                ; * 2
  151.         SUB     AX,AX               ; Get a zero
  152.         MOV     ES,AX               ; Put in ES so data is in absolute 0
  153.         MOV     ES:rs232_bios_address[BX],CX   ; Put address in BIOS table
  154.  
  155. init_not_bios:
  156.  
  157. ;--------------------------------------------------------------------------;
  158. ; Initialize the buffer addresses.                                         ;
  159. ;--------------------------------------------------------------------------;
  160.  
  161.         CALL    get_a_buffer        ; Get a buffer (of course!)
  162.         MOV     buffer_r_a[SI],AX   ; Put it away for receive
  163.         MOV     ES,AX               ; Clear any chains
  164.         MOV     ES:buffer_next,0    ;
  165.  
  166. ;--------------------------------------------------------------------------;
  167. ; If we have an 8250 or QuadPort or a 4 asyc port card with transmit       ;
  168. ; buffering, get an extra buffer                                           ;
  169. ;--------------------------------------------------------------------------;
  170.  
  171.         TEST    options[SI],opt_trbuf ; Transmit buffering turned on?
  172.         JZ      init_buffer_not     ;     Nope... No extra buffer needed
  173.  
  174.         CMP     chip[SI],chip_8250  ; Is this an 8250?
  175.         JE      init_buffer_textra  ;     Yep, lets do it
  176.         CMP     chip[SI],chip_qrqp  ; Is this a QuadRam QuadPort?
  177.         JE      init_buffer_textra  ;     Yep, lets do it
  178.         CMP     chip[SI],chip_4apc  ; Is this a 4 async port card?
  179.         JNE     init_buffer_not     ;     Nope... Skip
  180.  
  181. init_buffer_textra:
  182.  
  183.         CALL    get_a_buffer        ; Get a buffer (of course!)
  184.         MOV     buffer_t_a[SI],AX   ; Put it away for transmit
  185.  
  186.         TEST    options[SI],opt_hdwhs ; Hardware handshaking desired?
  187.         JZ      init_buffer_not     ;     Nope... No signal needed
  188.  
  189.         MOV     need_tmr,1          ; Handshaking/Transmit buffering
  190.                                     ; require timer grab
  191.  
  192. init_buffer_not:
  193.  
  194. ;--------------------------------------------------------------------------;
  195. ; Initialize the buffer ring pointers                                      ;
  196. ;--------------------------------------------------------------------------;
  197.  
  198.         SUB     AX,AX               ; Start of buffer is offset zero
  199.         MOV     buffer_r_in[SI],AX  ; Put in the buffer pointers
  200.         MOV     buffer_r_out[SI],AX ; Put in the buffer pointers
  201.         MOV     buffer_t_in[SI],AX  ; Put in the buffer pointers
  202.         MOV     buffer_t_out[SI],AX ; Put in the buffer pointers
  203.  
  204. ;--------------------------------------------------------------------------;
  205. ; Enable the interrupts for this device                                    ;
  206. ;--------------------------------------------------------------------------;
  207.  
  208.         TEST    options[SI],opt_high_irq ; Slave 8259 involved?
  209.         JNZ     init_pic_slave           ; Yep
  210.  
  211.         IN      AL,pic_mask_port    ; Set up 8259 master interupt controller
  212.         AND     AL,int_mask[SI]     ; Enable the interrupts for this device
  213.         OUT     pic_mask_port,AL    ;
  214.         JMP     SHORT init_pic_done ;
  215.  
  216. init_pic_slave:
  217.         IN      AL,pic2_mask_port   ; Set up 8259 slave interupt controller
  218.         AND     AL,int_mask[SI]     ; Enable the interrupts for this device
  219.         OUT     pic2_mask_port,AL   ;
  220. init_pic_done:
  221.  
  222. ;--------------------------------------------------------------------------;
  223. ; Quad port init                                                           ;
  224. ;--------------------------------------------------------------------------;
  225.  
  226.  IF present_qrqp
  227.    INCLUDE QRQPINI.ASM
  228.  ENDIF
  229.  
  230. ;--------------------------------------------------------------------------;
  231. ; buffer jump                                                              ;
  232. ;--------------------------------------------------------------------------;
  233.  
  234.         JMP     mbbinit_buffer_jump1
  235.         ORG     buffer_start + 2*buffer_size ;
  236. mbbinit_buffer_jump1:
  237.  
  238. ;--------------------------------------------------------------------------;
  239. ; 8250 init                                                                ;
  240. ;--------------------------------------------------------------------------;
  241.  
  242.  IF present_8250
  243.    INCLUDE 8250INI.ASM
  244.  ENDIF
  245.  
  246. ;--------------------------------------------------------------------------;
  247. ; 8530 init                                                                ;
  248. ;--------------------------------------------------------------------------;
  249.  
  250.  IF present_8530
  251.    INCLUDE 8530INI.ASM
  252.  ENDIF
  253.  
  254. ;--------------------------------------------------------------------------;
  255. ; Loop thru the next comm port                                             ;
  256. ;--------------------------------------------------------------------------;
  257.  
  258.         MOV     SI,com_next[SI]     ; Pointer to next com port block
  259.  
  260.         CMP     SI,0                ; Anything left to be done?
  261.         JE      com_done            ;      Nope...
  262.         JMP     init_loop           ;      Yep.. Loop back
  263. com_done:
  264.  
  265. ;--------------------------------------------------------------------------;
  266. ; Now snatch the timer vector                                              ;
  267. ;--------------------------------------------------------------------------;
  268.  
  269.         CMP     need_tmr,0          ; Need timer?
  270.         JE      no_time_vector_init ;      Nope.. Don't grab timer interrupt
  271.  
  272.         MOV     AH,dos_get_vector   ; DOS call #35H -- Get vector
  273.         MOV     AL,timer_vector_no  ; vector #
  274.         INT     dos_vector_no       ; Do it
  275.  
  276.         MOV     timer_old,BX        ;      and save it
  277.         MOV     timer_old+2,ES      ;
  278.  
  279.         MOV     AH,dos_set_vector   ; DOS call #25H -- Set vector
  280.         MOV     AL,timer_vector_no  ; RS232 vector #
  281.         MOV     DX,OFFSET timer_int ; Our vector address
  282.                                     ; DS already points to correct segment
  283.         INT     dos_vector_no       ; Do it
  284.  
  285. no_time_vector_init:                ;
  286.  
  287. ;--------------------------------------------------------------------------;
  288. ; Enable interrupts                                                        ;
  289. ;--------------------------------------------------------------------------;
  290.  
  291.         STI                         ; Enable CPU to receive interupts
  292.